<?php

require_once('db_access.php');

function connectDB($server,$user,$password,$dbname) {

	$link = mysqli_connect($server, $user, $password, $dbname)
		or die("Database Connect Failed: " . mysqli_connect_error());

	return $link;
}

function changeDateFormat($cdate){

	list($day,$month,$year)=explode("/",$cdate);

	return $year."-".$month."-".$day;
}

function storeData() {
	
	//*****************************************************************
	//Application Data
	//*****************************************************************	
	
	$ApplicantColumns = ""; //initialize strings
	$ApplicantValues = "";
	$DBApplicantQuery = "";
	
	if (isset($_POST["drpTitle"])) {
		$ApplicantColumns .= "Title";
		$ApplicantValues .= "'".$_POST["drpTitle"]."'";
	}
	if (isset($_POST["txtSurname"])) {
		$ApplicantColumns .= ",Surname";
		$ApplicantValues .= ",'" . $_POST["txtSurname"] . "'";
	}
	if (isset($_POST["txtOthername"])) {
		$ApplicantColumns .= ",OtherName";
		$ApplicantValues .= ",'" . $_POST["txtOthername"] . "'";
	}
	if (isset($_POST["txtDOB"])) {
		$ApplicantColumns .= ",DateOfBirth";
		$InsertDOBDate = changeDateFormat($_POST["txtDOB"]);
		$ApplicantValues .= ",'" . $InsertDOBDate . "'";
	}
	if (isset($_POST["drpSex"])) {
		$InsertSex = "M"; //default in .html form
		if ($_POST["drpSex"] == "Female")
			$InsertSex = "F";
		$ApplicantColumns .= ",Sex";
		$ApplicantValues .= ",'" . $InsertSex . "'";
	}
	if (isset($_POST["txtAddress"])) {
		$ApplicantColumns .= ",Address";
		$ApplicantValues .= ",'" . $_POST["txtAddress"] . "'";
	}
	if (isset($_POST["txtEmail"])) {
		$ApplicantColumns .= ",Email";
		$ApplicantValues .= ",'" . $_POST["txtEmail"] . "'";
	}
	if (isset($_POST["txtPhone"])) {
		$ApplicantColumns .= ",Telephone";
		$ApplicantValues .= ",'" . $_POST["txtPhone"] . "'";
	}
	if (isset($_POST["txtPlaceofbirth"])) {
		$ApplicantColumns .= ",Birthplace";
		$ApplicantValues .= ",'" . $_POST["txtPlaceofbirth"] . "'";
	}
	if (isset($_POST["txtNationality"])) {
		$ApplicantColumns .= ",Nationality";
		$ApplicantValues .= ",'" . $_POST["txtNationality"] . "'";
	}
	if (isset($_POST["txtHometown"])) {
		$ApplicantColumns .= ",Hometown";
		$ApplicantValues .= ",'" . $_POST["txtHometown"] . "'";
	}
	if (isset($_POST["txtRegion"])) {
		$ApplicantColumns .= ",Region";
		$ApplicantValues .= ",'" . $_POST["txtRegion"] . "'";
	}
	if (isset($_POST["txtReligion"])) {
		$ApplicantColumns .= ",Religion";
		$ApplicantValues .= ",'" . $_POST["txtReligion"] . "'";
	}
	if (isset($_POST["txtImpairment"])) {
		$ApplicantColumns .= ",Impairment";
		$ApplicantValues .= ",'" . $_POST["txtImpairment"] . "'";
	}
	if (isset($_POST["program"])) {
		$InsertProgram = "MLA";
		if($_POST["program"] == "MLT")
			$InsertProgram = "MLT";
		if($_POST["program"] == "DMLT")
			$InsertProgram = "DMLT";
		$ApplicantColumns .= ",Program";
		$ApplicantValues .= ",'" . $InsertProgram . "'";
	}

	if (isset($_POST["drpTitle"])) { //only time application query will be empty is if this page is visited from a location other than the html file

		$DBApplicantQuery = "INSERT INTO Applicant (".$ApplicantColumns.") VALUES (".$ApplicantValues.")";//must have semicolon inside quotes for multi-querying

		//initial query information - used to insert Applicant information then get auto-generated ID for other querys
		$FirstLink = mysql_connect($db_hostname,$db_username,$db_password)
			or die("Database Initial Connect Failed: " . mysql_connect_error());
		
		mysql_select_db($db_database, $FirstLink)
			or die("Database Selection Failed: " . mysql_error());
		
		//Insert Applicant Data
		mysql_query($DBApplicantQuery, $FirstLink)
			or die("Database Applicant Information Insert Failed: " . mysql_error());

		$CurrentApplicantID = mysql_insert_id();
		
		//***Query to update notifications table along with Applicant table***
		$DBNotificationsQuery = "INSERT INTO Notifications (ApplicantID,NotificationDate) VALUES (".$CurrentApplicantID.",NOW())";//must have semicolon inside quotes for multi-querying
		
		//Add update to notifications table
		mysql_query($DBNotificationsQuery, $FirstLink)
			or die("Database Applicant Information Insert Failed: " . mysql_error());

		mysql_close($FirstLink);
	}
	
	//*****************************************************************
	//Education Data
	//*****************************************************************	
	
	$EducationColumns1 = "ApplicantID"; //initialize strings (Foreign Key "ApplicantID" added as first argument)
	$EducationValues1 = "'".$CurrentApplicantID."'";
	$EducationColumns2 = "ApplicantID";
	$EducationValues2 = "'".$CurrentApplicantID."'";
	$EducationColumns3 = "ApplicantID";
	$EducationValues3 = "'".$CurrentApplicantID."'";
	$DBEducationQuery1 = "";
	$DBEducationQuery2 = "";
	$DBEducationQuery3 = "";
	$DBEducationQuery = ""; //overall query that combines 1, 2 and 3
	
	if (isset($_POST["txtSecschools1"])) {
		$EducationColumns1 .= ",SchoolNameLocation"; 
		$EducationValues1 .= ",'".$_POST["txtSecschools1"]."'";
			
		if (isset($_POST["txtOffices1"])) {
			$EducationColumns1 .= ",OfficesHeld"; 
			$EducationValues1 .= ",'" . $_POST["txtOffices1"]."'";
		}	
		else//Default value is "None"
		{
			$EducationColumns3 .= ",OfficesHeld"; 
			$EducationValues3 .= ",None";
		}
		if (isset($_POST["txtSchoolsStartDate1"])) {
			$EducationColumns1 .= ",StartDate"; 
			$InsertStartDate1 = changeDateFormat($_POST["txtSchoolsStartDate1"]);		
			$EducationValues1 .= ",'" . $InsertStartDate1."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtSchoolsEndDate1"])) {
			$EducationColumns1 .= ",EndDate"; 
			$InsertEndDate1 = changeDateFormat($_POST["txtSchoolsEndDate1"]);		
			$EducationValues1 .= ",'" . $InsertEndDate1."'";
		}
		else
		{/*validation error b/c field is required*/}
		
		$DBEducationQuery1 = "INSERT INTO EducationHistory (".$EducationColumns1.") VALUES (".$EducationValues1.");";//must have semicolon inside quotes for multi-querying
	}	
		
	if (isset($_POST["txtSecschools2"])) {
		$EducationColumns2 .= ",SchoolNameLocation"; 
		$EducationValues2 .= ",'".$_POST["txtSecschools2"]."'";
				
		if (isset($_POST["txtOffices2"])) {
			$EducationColumns2 .= ",OfficesHeld"; 
			$EducationValues2 .= ",'" . $_POST["txtOffices2"]."'";
		}	
		else//Default value is "None"
		{
			$EducationColumns3 .= ",OfficesHeld"; 
			$EducationValues3 .= ",None";
		}
		if (isset($_POST["txtSchoolsStartDate2"])) {
			$EducationColumns2 .= ",StartDate"; 
			$InsertStartDate2 = changeDateFormat($_POST["txtSchoolsStartDate2"]);		
			$EducationValues2 .= ",'" . $InsertStartDate2."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtSchoolsEndDate2"])) {
			$EducationColumns2 .= ",EndDate"; 
			$InsertEndDate2 = changeDateFormat($_POST["txtSchoolsEndDate2"]);		
			$EducationValues2 .= ",'" . $InsertEndDate2."'";
		}
		else
		{/*validation error b/c field is required*/}
		
		$DBEducationQuery2 = "INSERT INTO EducationHistory (".$EducationColumns2.") VALUES (".$EducationValues2.");";//must have semicolon inside quotes for multi-querying
	}
		
	if (isset($_POST["txtSecschools3"])) {
		$EducationColumns3 .= ",SchoolNameLocation"; 
		$EducationValues3 .= ",'".$_POST["txtSecschools3"]."'";
		
		if (isset($_POST["txtOffices3"])) {
			$EducationColumns3 .= ",OfficesHeld"; 
			$EducationValues3 .= ",'" . $_POST["txtOffices3"]."'";
		}	
		else //Default value is "None"
		{
			$EducationColumns3 .= ",OfficesHeld"; 
			$EducationValues3 .= ",None";
		}
		if (isset($_POST["txtSchoolsStartDate3"])) {
			$EducationColumns3 .= ",StartDate"; 
			$InsertStartDate3 = changeDateFormat($_POST["txtSchoolsStartDate3"]);		
			$EducationValues3 .= ",'" . $InsertStartDate3."'";
		}
		else
		{/*validation error b/c field is required*/}	
		if (isset($_POST["txtSchoolsEndDate3"])) {
			$EducationColumns3 .= ",EndDate"; 
			$InsertEndDate3 = changeDateFormat($_POST["txtSchoolsEndDate3"]);		
			$EducationValues3 .= ",'" . $InsertEndDate3."'";
		}
		else
		{/*validation error b/c field is required*/}

		$DBEducationQuery3 = "INSERT INTO EducationHistory (".$EducationColumns3.") VALUES (".$EducationValues3.");";//must have semicolon inside quotes for multi-querying
	}
	
	if ($DBEducationQuery1 != "")
		$DBEducationQuery .= $DBEducationQuery1;
	if ($DBEducationQuery2 != "")
		$DBEducationQuery .= $DBEducationQuery2;
	if ($DBEducationQuery3 != "")
		$DBEducationQuery .= $DBEducationQuery3;
	
	//*****************************************************************
	//Exam Data
	//*****************************************************************	
	
	$ExamColumns1 = "ApplicantID";  //initialize strings (Foreign Key "ApplicantID" added as first argument)
	$ExamValues1 = "'".$CurrentApplicantID."'";
	$ExamColumns2 = "ApplicantID";
	$ExamValues2 = "'".$CurrentApplicantID."'";
	$ExamColumns3 = "ApplicantID";
	$ExamValues3 = "'".$CurrentApplicantID."'";
	$DBExamQuery1 = "";
	$DBExamQuery2 = "";
	$DBExamQuery3 = "";
	$DBExamQuery = ""; //overall query that combines 1, 2 and 3
	
	if (isset($_POST["txtExamName1"])) {
		$ExamColumns1 .= ",ExamName"; 
		$ExamValues1 .= ",'".$_POST["txtExamName1"]."'";
			
		if (isset($_POST["txtExamYear1"])) {
			$ExamColumns1 .= ",ExamYear"; 
			$ExamValues1 .= ",'".$_POST["txtExamYear1"]."'";
		}
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtExamIndex1"])) {
			$ExamColumns1 .= ",ExamIndex"; 
			$ExamValues1 .= ",'".$_POST["txtExamIndex1"]."'";
		}
		
		$ExamColumns1 .= ",Attempt";
		$ExamValues1 .= ",1";
		
		$DBExamQuery1 = "INSERT INTO ExamHistory (".$ExamColumns1.") VALUES (".$ExamValues1.");";//must have semicolon inside quotes for multi-querying
	}	
	if (isset($_POST["txtExamName2"])) {
		$ExamColumns2 .= ",ExamName"; 
		$ExamValues2 .= ",'".$_POST["txtExamName2"]."'";
			
		if (isset($_POST["txtExamYear2"])) {
			$ExamColumns2 .= ",ExamYear"; 
			$ExamValues2 .= ",'".$_POST["txtExamYear2"]."'";
		}
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtExamIndex2"])) {
			$ExamColumns2 .= ",ExamIndex"; 
			$ExamValues2 .= ",'".$_POST["txtExamIndex2"]."'";
		}
		
		$ExamColumns2 .= ",Attempt";
		$ExamValues2 .= ",2";
		
		$DBExamQuery2 = "INSERT INTO ExamHistory (".$ExamColumns2.") VALUES (".$ExamValues2.");";//must have semicolon inside quotes for multi-querying
	}	
	if (isset($_POST["txtExamName3"])) {
		$ExamColumns3 .= ",ExamName"; 
		$ExamValues3 .= ",'".$_POST["txtExamName3"]."'";
			
		if (isset($_POST["txtExamYear3"])) {
			$ExamColumns3 .= ",ExamYear"; 
			$ExamValues3 .= ",'".$_POST["txtExamYear3"]."'";
		}
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtExamIndex3"])) {
			$ExamColumns3 .= ",ExamIndex"; 
			$ExamValues3 .= ",'".$_POST["txtExamIndex3"]."'";
		}
		
		$ExamColumns3 .= ",Attempt";
		$ExamValues3 .= ",3";
		
		$DBExamQuery3 = "INSERT INTO ExamHistory (".$ExamColumns3.") VALUES (".$ExamValues3.");";//must have semicolon inside quotes for multi-querying
	}
	
	if ($DBExamQuery1 != "")
		$DBExamQuery .= $DBExamQuery1;
	if ($DBExamQuery2 != "")
		$DBExamQuery .= $DBExamQuery2;
	if ($DBExamQuery3 != "")
		$DBExamQuery .= $DBExamQuery3;
	
	//*****************************************************************
	//Grades Data
	//*****************************************************************	
	
	$GradesColumns1 = "ApplicantID";  //initialize strings (Foreign Key "ApplicantID" added as first argument)
	$GradesValues1 = "'".$CurrentApplicantID."'";
	$GradesColumns2 = "ApplicantID";
	$GradesValues2 = "'".$CurrentApplicantID."'";
	$GradesColumns3 = "ApplicantID";
	$GradesValues3 = "'".$CurrentApplicantID."'";
	$GradesColumns4 = "ApplicantID";
	$GradesValues4 = "'".$CurrentApplicantID."'";
	$GradesColumns5 = "ApplicantID";
	$GradesValues5 = "'".$CurrentApplicantID."'";
	$GradesColumns6 = "ApplicantID";
	$GradesValues6 = "'".$CurrentApplicantID."'";
	$GradesColumns7 = "ApplicantID";
	$GradesValues7 = "'".$CurrentApplicantID."'";
	$GradesColumns8 = "ApplicantID";
	$GradesValues8 = "'".$CurrentApplicantID."'";
	$DBGradesQuery1 = "";
	$DBGradesQuery2 = "";
	$DBGradesQuery3 = "";
	$DBGradesQuery4 = "";
	$DBGradesQuery5 = "";
	$DBGradesQuery6 = "";
	$DBGradesQuery7 = "";
	$DBGradesQuery8 = "";
	$DBGradesQuery = ""; //overall query that combines 1, 2 and 3
	
	if (isset($_POST["txtGradesSubject1"])) {
		$GradesColumns1 .= ",Subject"; 
		$GradesValues1 .= ",'".$_POST["txtGradesSubject1"]."'";
		
		if (isset($_POST["txtGradesFirst1"])) {
			$GradesColumns1 .= ",Attempt1"; 
			$GradesValues1 .= ",'".$_POST["txtGradesFirst1"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond1"])) {
			$GradesColumns1 .= ",Attempt2"; 
			$GradesValues1 .= ",'".$_POST["txtGradesSecond1"]."'";
		}	
		if (isset($_POST["txtGradesThird1"])) {
			$GradesColumns1 .= ",Attempt3"; 
			$GradesValues1 .= ",'".$_POST["txtGradesThird1"]."'";
		}
		
		$DBGradesQuery1 = "INSERT INTO GradeHistory (".$GradesColumns1.") VALUES (".$GradesValues1.");";//must have semicolon inside quotes for multi-querying
	}
	if (isset($_POST["txtGradesSubject2"])) {
		$GradesColumns2 .= ",Subject"; 
		$GradesValues2 .= ",'".$_POST["txtGradesSubject2"]."'";
		
		if (isset($_POST["txtGradesFirst2"])) {
			$GradesColumns2 .= ",Attempt1"; 
			$GradesValues2 .= ",'".$_POST["txtGradesFirst2"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond2"])) {
			$GradesColumns2 .= ",Attempt2"; 
			$GradesValues2 .= ",'".$_POST["txtGradesSecond2"]."'";
		}	
		if (isset($_POST["txtGradesThird2"])) {
			$GradesColumns2 .= ",Attempt3"; 
			$GradesValues2 .= ",'".$_POST["txtGradesThird2"]."'";
		}
		
		$DBGradesQuery2 = "INSERT INTO GradeHistory (".$GradesColumns2.") VALUES (".$GradesValues2.");";//must have semicolon inside quotes for multi-querying
	}		
	if (isset($_POST["txtGradesSubject3"])) {
		$GradesColumns3 .= ",Subject"; 
		$GradesValues3 .= ",'".$_POST["txtGradesSubject3"]."'";
		
		if (isset($_POST["txtGradesFirst3"])) {
			$GradesColumns3 .= ",Attempt1"; 
			$GradesValues3 .= ",'".$_POST["txtGradesFirst3"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond3"])) {
			$GradesColumns3 .= ",Attempt2"; 
			$GradesValues3 .= ",'".$_POST["txtGradesSecond3"]."'";
		}	
		if (isset($_POST["txtGradesThird3"])) {
			$GradesColumns3 .= ",Attempt3"; 
			$GradesValues3 .= ",'".$_POST["txtGradesThird3"]."'";
		}
		
		$DBGradesQuery3 = "INSERT INTO GradeHistory (".$GradesColumns3.") VALUES (".$GradesValues3.");";//must have semicolon inside quotes for multi-querying
	}	
	if (isset($_POST["txtGradesSubject4"])) {
		$GradesColumns4 .= ",Subject"; 
		$GradesValues4 .= ",'".$_POST["txtGradesSubject4"]."'";
		
		if (isset($_POST["txtGradesFirst4"])) {
			$GradesColumns4 .= ",Attempt1"; 
			$GradesValues4 .= ",'".$_POST["txtGradesFirst4"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond4"])) {
			$GradesColumns4 .= ",Attempt2"; 
			$GradesValues4 .= ",'".$_POST["txtGradesSecond4"]."'";
		}	
		if (isset($_POST["txtGradesThird4"])) {
			$GradesColumns4 .= ",Attempt3"; 
			$GradesValues4 .= ",'".$_POST["txtGradesThird4"]."'";
		}
		
		$DBGradesQuery4 = "INSERT INTO GradeHistory (".$GradesColumns4.") VALUES (".$GradesValues4.");";//must have semicolon inside quotes for multi-querying
	}	
	if (isset($_POST["txtGradesSubject5"])) {
		$GradesColumns5 .= ",Subject"; 
		$GradesValues5 .= ",'".$_POST["txtGradesSubject5"]."'";
			
		if (isset($_POST["txtGradesFirst5"])) {
			$GradesColumns5 .= ",Attempt1"; 
			$GradesValues5 .= ",'".$_POST["txtGradesFirst5"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond5"])) {
			$GradesColumns5 .= ",Attempt2"; 
			$GradesValues5 .= ",'".$_POST["txtGradesSecond5"]."'";
		}	
		if (isset($_POST["txtGradesThird5"])) {
			$GradesColumns5 .= ",Attempt3"; 
			$GradesValues5 .= ",'".$_POST["txtGradesThird5"]."'";
		}
		
		$DBGradesQuery5 = "INSERT INTO GradeHistory (".$GradesColumns5.") VALUES (".$GradesValues5.");";//must have semicolon inside quotes for multi-querying
	}	
	if (isset($_POST["txtGradesSubject6"])) {
		$GradesColumns6 .= ",Subject"; 
		$GradesValues6 .= ",'".$_POST["txtGradesSubject6"]."'";
		
		if (isset($_POST["txtGradesFirst6"])) {
			$GradesColumns6 .= ",Attempt1"; 
			$GradesValues6 .= ",'".$_POST["txtGradesFirst6"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond6"])) {
			$GradesColumns6 .= ",Attempt2"; 
			$GradesValues6 .= ",'".$_POST["txtGradesSecond6"]."'";
		}	
		if (isset($_POST["txtGradesThird6"])) {
			$GradesColumns6 .= ",Attempt3"; 
			$GradesValues6 .= ",'".$_POST["txtGradesThird6"]."'";
		}
		
		$DBGradesQuery6 = "INSERT INTO GradeHistory (".$GradesColumns6.") VALUES (".$GradesValues6.");";//must have semicolon inside quotes for multi-querying
	}	
	if (isset($_POST["txtGradesSubject7"])) {
		$GradesColumns7 .= ",Subject"; 
		$GradesValues7 .= ",'".$_POST["txtGradesSubject7"]."'";
			
		if (isset($_POST["txtGradesFirst7"])) {
			$GradesColumns7 .= ",Attempt1"; 
			$GradesValues7 .= ",'".$_POST["txtGradesFirst7"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond7"])) {
			$GradesColumns7 .= ",Attempt2"; 
			$GradesValues7 .= ",'".$_POST["txtGradesSecond7"]."'";
		}	
		if (isset($_POST["txtGradesThird7"])) {
			$GradesColumns7 .= ",Attempt3"; 
			$GradesValues7 .= ",'".$_POST["txtGradesThird7"]."'";
		}	
		
		$DBGradesQuery7 = "INSERT INTO GradeHistory (".$GradesColumns7.") VALUES (".$GradesValues7.");";//must have semicolon inside quotes for multi-querying
	}
	if (isset($_POST["txtGradesSubject8"])) {
		$GradesColumns8 .= ",Subject"; 
		$GradesValues8 .= ",'".$_POST["txtGradesSubject8"]."'";
		
		if (isset($_POST["txtGradesFirst8"])) {
			$GradesColumns8 .= ",Attempt1"; 
			$GradesValues8 .= ",'".$_POST["txtGradesFirst8"]."'";
		}	
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtGradesSecond8"])) {
			$GradesColumns8 .= ",Attempt2"; 
			$GradesValues8 .= ",'".$_POST["txtGradesSecond8"]."'";
		}	
		if (isset($_POST["txtGradesThird8"])) {
			$GradesColumns8 .= ",Attempt3"; 
			$GradesValues8 .= ",'".$_POST["txtGradesThird8"]."'";
		}
		
		$DBGradesQuery8 = "INSERT INTO GradeHistory (".$GradesColumns8.") VALUES (".$GradesValues8.");";//must have semicolon inside quotes for multi-querying
	}
	
	if ($DBGradesQuery1 != "")
		$DBGradesQuery .= $DBGradesQuery1;
	if ($DBGradesQuery2 != "")
		$DBGradesQuery .= $DBGradesQuery2;
	if ($DBGradesQuery3 != "")
		$DBGradesQuery .= $DBGradesQuery3;
	if ($DBGradesQuery4 != "")
		$DBGradesQuery .= $DBGradesQuery4;
	if ($DBGradesQuery5 != "")
		$DBGradesQuery .= $DBGradesQuery5;
	if ($DBGradesQuery6 != "")
		$DBGradesQuery .= $DBGradesQuery6;
	if ($DBGradesQuery7 != "")
		$DBGradesQuery .= $DBGradesQuery7;
	if ($DBGradesQuery8 != "")
		$DBGradesQuery .= $DBGradesQuery8;
	
	//*****************************************************************
	//Emergency Contact Data
	//*****************************************************************	
	
	$ECColumns = "ApplicantID";  //initialize strings (Foreign Key "ApplicantID" added as first argument)
	$ECValues = "'".$CurrentApplicantID."'";
	$DBEmergencyContactQuery = "";
		
	if (isset($_POST["txtParentName"])) {
		$ECColumns .= ",ContactName"; 
		$ECValues .= ",'".$_POST["txtParentName"]."'";	
		
		if (isset($_POST["txtParentRelation"])) {
			$ECColumns .= ",Relationship"; 
			$ECValues .= ",'".$_POST["txtParentRelation"]."'";
		}
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtParentAddress"])) {
			$ECColumns .= ",Address"; 
			$ECValues .= ",'".$_POST["txtParentAddress"]."'";
		}
		else
		{/*validation error b/c field is required*/}
		if (isset($_POST["txtParentPhone"])) {
			$ECColumns .= ",Telephone"; 
			$ECValues .= ",'".$_POST["txtParentPhone"]."'";
		}	
		if (isset($_POST["txtParentEMail"])) {
			$ECColumns .= ",EMail"; 
			$ECValues .= ",'".$_POST["txtParentEMail"]."'";
		}	
		if (isset($_POST["txtParentOccupation"])) {
			$ECColumns .= ",Occupation"; 
			$ECValues .= ",'".$_POST["txtParentOccupation"]."'";
		}
		
		$DBEmergencyContactQuery = "INSERT INTO EmergencyContact (".$ECColumns.") VALUES (".$ECValues.");";//must have semicolon inside quotes for multi-querying
	}
	
	//*****************************************************************
	//Witness Data
	//*****************************************************************	
	
	$WitnessColumns = "ApplicantID";  //initialize strings (Foreign Key "ApplicantID" added as first argument)
	$WitnessValues = "'".$CurrentApplicantID."'";
	$DBWitnessQuery = "";
		
	if (isset($_POST["txtWitnessName"])) {
		$WitnessColumns .= ",WitnessName"; 
		$WitnessValues .= ",'" . $_POST["txtWitnessName"]."'";
		
		if (isset($_POST["txtWitnessStatus"])) {
			$WitnessColumns .= ",Status"; 
			$WitnessValues .= ",'" . $_POST["txtWitnessStatus"]."'";
		}	
		if (isset($_POST["txtWitnessAddress"])) {
			$WitnessColumns .= ",Address"; 
			$WitnessValues .= ",'" . $_POST["txtWitnessAddress"]."'";
		}
	
		$DBWitnessQuery .= "INSERT INTO Witness (".$WitnessColumns.") VALUES (".$WitnessValues.")";//no semicolon inside quotes necessary because its the last query
	}
	
	//***Connection/Multi-Query Information******	
	$DBLink = connectDB($db_hostname,$db_username,$db_password, $db_database);
	
	//Build Multi-Query
	$DBQuery = "";
	if(!empty($DBEducationQuery))
		$DBQuery .= $DBEducationQuery;
	if(!empty($DBExamQuery))
		$DBQuery .= $DBExamQuery;
	if(!empty($DBGradesQuery))
		$DBQuery .= $DBGradesQuery;
	if(!empty($DBEmergencyContactQuery))
		$DBQuery .= $DBEmergencyContactQuery;
	if(!empty($DBWitnessQuery))
		$DBQuery .= $DBWitnessQuery;
	
	mysqli_multi_query($DBLink, $DBQuery)
		or die("Problem Inserting Data Into Database: " . mysqli_error($DBLink));
		
	mysqli_close($DBLink);
}

storeData();

?>

<html>
<head>
    <title>Print Form</title>
<style type="text/css">
	@media print {
		body * {
			visibility: hidden;
		}
		
		#divNoPrint * {
			display: none;
		}
		
		#divPrint * {
			visibility: visible;
		}
	}
	
	table.bordered {
		border-width: thin;
		border-style: solid;
		}
	
	table.outlined {
		border-collapse: collapse;
	}
	table.outlined th {
		border-width: thin;
		border-style: solid;
		padding: 3px;
	}
	table.outlined td {
		border-width: thin;
		border-style: solid;
		padding: 3px;
	}
	
	div.print {
		visibility: hidden;
		width: 7.5in;
	}
</style>
<script>
function printPage() {
	window.print();
	
	showElements();
}
function showElements() {
	document.getElementById("divInitialPrintBtn").style.display = "none";
	document.getElementById("divLinkHome").style.display = "block";	
}
</script>
</head>
<body>
<a name="pagetop"></a>

<div id="divNoPrint" style="margin:0% 25% 0% 25%">
<div id="divNoPrintTitle" align="center">
	<center><h1>KINGS NURSING AND ALLIED HEALTH COLLEGE LTD</h1></center>
	<br/>
	
	<div id="divConfirmation">
    <table>
        <tr>
			<td colspan="2">
				Thank you for applying at the Martin Luther King Medical Training School.
				<br/><br/>
				The next step of the process is to print out your information, obtain the necessary signatures, then bring the copy<br/>
				along with 25 dollars when you visit the school. For a printer-friendly version of the application form, with your<br/>
				information already applied, please click the "Print PDF" button below. If your computer does not have Adobe, and that<br/>
				button doesn't work, click the "Print HTML" button to print the page.
				<br/><br/>
				
				<div id="divInitialPrintBtn">
					<form id="Initial Print Form" name="Initial Print Form" action="print-pdf.php" method="POST">
						<?php
							foreach ($_POST as $key=>$value) {
								echo "<input type='hidden' name='" . htmlspecialchars($key) ."' value='" . htmlspecialchars($value) . "'/>";
							}
						?>
						<table>
							<tr>
								<td align="center"><input type="submit" value="Print PDF" onClick="showElements();"/></td>
								<td align="center"><input type="button" value="Print HTML" onClick="printPage();"/></td>
							</tr>
						</table>
					</form>
				</div>
            </td>
		</tr>
    </table>
    </div>
	
	<div id="divLinkHome" style="display:none">
	<form id="Print Form" name="Print Form" action="print-pdf.php" method="POST">
		<?php
			foreach ($_POST as $key=>$value) {
				echo "<input type='hidden' name='" . htmlspecialchars($key) ."' value='" . htmlspecialchars($value) . "'/>";
			}
		?>
		<table>
			<tr>
				<td colspan="3">
					Once your application has printed, you may either close this page or follow the link to the home page.
					<br/><br/>
				</td>
			</tr>
			<tr>
				<td align="center"><a href="~~~link to home page~~~">Back to Home</a></td>
				<td align="center"><input type="submit" value="Print PDF" onClick="showElements();"/></td>
				<td align="center"><input type="button" value="Print HTML" onClick="printPage();"/></td>			
			</tr>
		</table>
	</form>
	</div>	
</div>
</div>

<div id="divPrint" class="print">

<div id="divTitle" align="center">
	<h1>KINGS NURSING AND ALLIED HEALTH COLLEGE LTD</h1>
	<br/>

<div id="divValidationMessage" style="display:none">
	<h3><font color="red">
	We're Sorry. But the fields below must be filled out before we can continue processing
	your information.<br/>Answer the remaining questions and click the "Submit Application" button to
	continue.
	</font></h3>
</div>
<div id="divReviewMessage" style="display:none">
	<h3><font color="blue">
	Please review your information to ensure everything is correct before your application<br/>
	is processed. Once you are sure everything is accurate, click the "Submit Application" button<br/>
	again to finalize your application.
	</font></h3>
</div>
</div>

<div id="divContactInfo">
<h3>P.O. BOX 89, DANSOMAN ACCRA</h3>
<pre>
Tel: 233-21-315870	Mobile: 0208185454
E-Mail: MLKMC@rogers.com
</pre>
<br/><br/>
</div>

<div id="divFormInfo">
<table>
	<tr>
	<td>
		<h3>APPLICATION FORM</h3>
	</td>
	<td rowspan="2">
		<table class="bordered">
		<tr><td>
		<br/><br/><br/>
		<center>Fix Passport Picture Here</center>
		<br/><br/><br/>
		</td></tr>
		</table>
	</td>
	</tr>
	<tr>
	<td>
		i.  Certified photocopy of result slips;<br/>
		ii. Two recent passport-size photographs one of which should be fixed on the form.
		The remaining photograph should be endorsed. (See Declaration section)
	</td>
	<td></td>
	</tr>
</table>
<br/><br/>
</div>

<div  id="divName">
<h4>1. Name</h4>

<b>TITLE:</b>
<br/>
	<input type="text" id="txtTitle" style="border:none" value="<?php echo $_POST["drpTitle"]; ?>"/>
<br/><br/>
<b>SURNAME:</b>
<br/>
	<input type="text" id="txtSurname" style="border:none" size="<?php echo strlen($_POST["txtSurname"]);?>" value="<?php echo $_POST["txtSurname"]; ?>"/>
<br/><br/>
<b>OTHER NAME:</b>
<br/>
	<input type="text" id="txtOthername" style="border:none" size="<?php echo strlen($_POST["txtOthername"]);?>" value="<?php echo $_POST["txtOthername"]; ?>"/>
	<br/>
	(Ensure that names correspond with those used for all examinations taken. Provide legal proof for any change in name.)
<br/><br/>
</div>

<div id="divDOB">
<h4>2. Date of Birth (day, month, year)</h4>
<input type="text" id="txtDOB" style="border:none" value="<?php echo $_POST["txtDOB"];?>"/>
<br/><br/>
</div>

<div id="divSex">
<h4>3. Sex</h4>
<input type="text" id="txtSex" style="border:none" value="<?php echo $_POST["drpSex"]; ?>"/>
<br/><br/>
</div>

<div id="divAddress">
<h4>4. Address to which communication regarding this application should be sent:</h4>
	<input type="text" id="txtAddress" style="border:none" size="<?php echo strlen($_POST["txtAddress"]);?>" value="<?php echo $_POST["txtAddress"]; ?>"/>
<br/><br/>
	<b>E-Mail Address:</b>
	<input type="text" id="txtEmail" style="border:none" size="<?php echo strlen($_POST["txtEmail"])+10;?>" value="<?php echo $_POST["txtEmail"]; ?>"/>
<br/>
	<b>Tel. No:</b>
	<input type="text" id="txtPhone" style="border:none" size="<?php echo strlen($_POST["txtPhone"]);?>" value="<?php echo $_POST["txtPhone"]; ?>"/>
<br/><br/>
</div>

<div id="divGeographics">
<h4>5. Geographics</h4>
<table>
	<tr>
		<td><b>i.</b></td>
		<td><b>Place of Birth</b></td>
		<td><input type="text" id="txtPlaceofbirth" style="border:none" size="<?php echo strlen($_POST["txtPlaceofbirth"]);?>" value="<?php echo $_POST["txtPlaceofbirth"]; ?>"/></td>
	</tr><tr>
		<td><b>ii.</b></td>
		<td><b>Nationality</b></td>
		<td><input type="text" id="txtNationality" style="border:none" size="<?php echo strlen($_POST["txtNationality"]);?>" value="<?php echo $_POST["txtNationality"]; ?>"/></td>
	</tr><tr>
		<td><b>iii.</b></td>
		<td><b>Home Town</b></td>
		<td><input type="text" id="txtHometown" style="border:none" size="<?php echo strlen($_POST["txtHometown"]);?>" value="<?php echo $_POST["txtHometown"]; ?>"/></td>
	</tr><tr>
		<td><b>iv.</b></td>
		<td><b>Region and Country</b></td>
		<td><input type="text" id="txtRegion" style="border:none" size="<?php echo strlen($_POST["txtRegion"]);?>" value="<?php echo $_POST["txtRegion"]; ?>"/></td>
	</tr><tr>
		<td><b>v.</b></td>
		<td><b>Religion</b></td>
		<td><input type="text" id="txtReligion" style="border:none" size="<?php echo strlen($_POST["txtReligion"]);?>" value="<?php echo $_POST["txtReligion"]; ?>"/></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divImpairments">
<b>6. Do you suffer from any form of impairment?</b>
	Yes
	<input type="radio" id="rdoYesimpairment" name="impairment" value="Yes" <?php if($_POST["rdoimpairment"]=="Yes"){echo "checked";}?>/>
	No
	<input type="radio" id="rdoNoimpairment" name="impairment" value="No" <?php if($_POST["rdoimpairment"]=="No"){echo "checked";}?>/>
<br/><br/>

<h4>7. If yes, please specify</h4>
    <textarea cols="50" rows="<?php echo strlen($_POST["txtImpairment"])/50;?>" id="txtImpairment" name="txtImpairment" value=""><?php echo $_POST["txtImpairment"]; ?></textarea>	
<br/><br/>
</div>

<div id="divEducation">
<h4>8. Education</h4>
<table class="outlined">
	<tr>
		<td valign="top"><center>Name of Secondary School/College & Location</center></td>
		<td valign="top"><center>Offices Held</center></td>
		<td><center>Attended Dates<br>(day, month, year)</center></td>
		<td rowspan="7" style="border:none">
		<div id="divEducationDatesError" style="display:none">
			<font color="red">Please enter start and end dates<br/>for each school attended.<br/>NOTE: Starting dates must<br/>be before ending dates.</font>
		</div>
		</td>
	</tr><tr>
		<td><input type="text" id="txtSecschools1" style="border:none" size="<?php echo strlen($_POST["txtSecschools1"]);?>" value="<?php echo $_POST["txtSecschools1"]; ?>"/></td>
		<td><input type="text" id="txtOffices1" style="border:none" size="<?php echo strlen($_POST["txtOffices1"]);?>" value="<?php echo $_POST["txtOffices1"]; ?>"/></td>
		<td>
			From: 
			<input type="text" id="txtSchoolsStart1" style="border:none" value="<?php echo $_POST["txtSchoolsStartDate1"];?>"/>
		</td>
	</tr><tr>
		<td></td><td></td>
		<td>
			To: 
			<input type="text" id="txtSchoolsEnd1" style="border:none" value="<?php echo $_POST["txtSchoolsEndDate1"];?>"/>
		</td>
	</tr><tr>
		<td><input type="text" id="txtSecschools2" style="border:none" size="<?php echo strlen($_POST["txtSecschools2"]);?>" value="<?php echo $_POST["txtSecschools2"]; ?>"/></td>
		<td><input type="text" id="txtOffices2" style="border:none" size="<?php echo strlen($_POST["txtOffices2"]);?>" value="<?php echo $_POST["txtOffices2"]; ?>"/></td>
		<td>
			From: 
			<input type="text" id="txtSchoolsStart2" style="border:none" value="<?php echo $_POST["txtSchoolsStartDate2"];?>"/>
		</td>
	</tr><tr>
		<td></td><td></td>
		<td>
			To: 
			<input type="text" id="txtSchoolsEnd2" style="border:none" value="<?php echo $_POST["txtSchoolsEndDate2"];?>"/>
		</td>
	</tr><tr>
		<td><input type="text" id="txtSecschools3" style="border:none" size="<?php echo strlen($_POST["txtSecschools3"]);?>" value="<?php echo $_POST["txtSecschools3"]; ?>"/></td>
		<td><input type="text" id="txtOffices3" style="border:none" size="<?php echo strlen($_POST["txtOffices3"]);?>" value="<?php echo $_POST["txtOffices3"]; ?>"/></td>
		<td>
			From: 
			<input type="text" id="txtSchoolsStart3" style="border:none" value="<?php echo $_POST["txtSchoolsStartDate3"];?>"/>
		</td>
	</tr><tr>
		<td></td><td></td>
		<td>
			To: 
			<input type="text" id="txtSchoolsEnd2" style="border:none" value="<?php echo $_POST["txtSchoolsEndDate3"];?>"/>
		</td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divExam">
<h4>9. Examination Details:</h4>
<table class="outlined">
	<tr>
		<td width="125"><b>Attempts</b></td>
		<td><center>1st</center></td>
		<td><center>2nd</center></td>
		<td><center>3rd</center></td>
	</tr><tr>
		<td><b>Name</b></td>
		<td><input type="text" id="txtExamName1" style="border:none" size="<?php echo strlen($_POST["txtExamName1"]);?>" value="<?php echo $_POST["txtExamName1"]; ?>"/></td>
		<td><input type="text" id="txtExamName2" style="border:none" size="<?php echo strlen($_POST["txtExamName2"]);?>" value="<?php echo $_POST["txtExamName2"]; ?>"/></td>
		<td><input type="text" id="txtExamName3" style="border:none" size="<?php echo strlen($_POST["txtExamName3"]);?>" value="<?php echo $_POST["txtExamName3"]; ?>"/></td>
	</tr><tr>
		<td><b>Year</b></td>
		<td><input type="text" id="txtExamYear1" style="border:none" size="<?php echo strlen($_POST["txtExamYear1"]);?>" value="<?php echo $_POST["txtExamYear1"]; ?>"/></td>
		<td><input type="text" id="txtExamYear2" style="border:none" size="<?php echo strlen($_POST["txtExamYear2"]);?>" value="<?php echo $_POST["txtExamYear2"]; ?>"/></td>
		<td><input type="text" id="txtExamYear3" style="border:none" size="<?php echo strlen($_POST["txtExamYear3"]);?>" value="<?php echo $_POST["txtExamYear3"]; ?>"/></td>
	</tr><tr>
		<td><b>Index No(s)</b></td>
		<td><input type="text" id="txtExamIndex1" style="border:none" size="<?php echo strlen($_POST["txtExamIndex1"]);?>" value="<?php echo $_POST["txtExamIndex1"]; ?>"/></td>
		<td><input type="text" id="txtExamIndex2" style="border:none" size="<?php echo strlen($_POST["txtExamIndex2"]);?>" value="<?php echo $_POST["txtExamIndex2"]; ?>"/></td>
		<td><input type="text" id="txtExamIndex3" style="border:none" size="<?php echo strlen($_POST["txtExamIndex3"]);?>" value="<?php echo $_POST["txtExamIndex3"]; ?>"/></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divGrades">
<h4>10. Grades Obtained</h4>
<table class="outlined">
	<tr>
		<td><center><b>Subjects</b></center></td>
		<td colspan="3"><center><b>Grades</b></center></td>
	</tr><tr>
		<td></td>
		<td><center>1st Attempt</center></td>
		<td><center>2nd Attempt</center></td>
		<td><center>3rd Attempt</center></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject1" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject1"]);?>" value="<?php echo $_POST["txtGradesSubject1"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst1" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst1"]);?>" value="<?php echo $_POST["txtGradesFirst1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond1" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond1"]);?>" value="<?php echo $_POST["txtGradesSecond1"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird1" style="border:none" size="<?php echo strlen($_POST["txtGradesThird1"]);?>" value="<?php echo $_POST["txtGradesThird1"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject2" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject2"]);?>" value="<?php echo $_POST["txtGradesSubject2"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst2" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst2"]);?>" value="<?php echo $_POST["txtGradesFirst2"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond2" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond2"]);?>" value="<?php echo $_POST["txtGradesSecond2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird2" style="border:none" size="<?php echo strlen($_POST["txtGradesThird2"]);?>" value="<?php echo $_POST["txtGradesThird2"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject3" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject3"]);?>" value="<?php echo $_POST["txtGradesSubject3"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst3" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst3"]);?>" value="<?php echo $_POST["txtGradesFirst3"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond3" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond3"]);?>" value="<?php echo $_POST["txtGradesSecond3"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird3" style="border:none" size="<?php echo strlen($_POST["txtGradesThird3"]);?>" value="<?php echo $_POST["txtGradesThird3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject4" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject4"]);?>" value="<?php echo $_POST["txtGradesSubject4"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst4" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst4"]);?>" value="<?php echo $_POST["txtGradesFirst4"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond4" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond4"]);?>" value="<?php echo $_POST["txtGradesSecond4"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird4" style="border:none" size="<?php echo strlen($_POST["txtGradesThird4"]);?>" value="<?php echo $_POST["txtGradesThird4"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject5" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject5"]);?>" value="<?php echo $_POST["txtGradesSubject5"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst5" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst5"]);?>" value="<?php echo $_POST["txtGradesFirst5"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond5" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond5"]);?>" value="<?php echo $_POST["txtGradesSecond5"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird5" style="border:none" size="<?php echo strlen($_POST["txtGradesThird5"]);?>" value="<?php echo $_POST["txtGradesThird5"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject6" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject6"]);?>" value="<?php echo $_POST["txtGradesSubject6"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst6" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst6"]);?>" value="<?php echo $_POST["txtGradesFirst6"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond6" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond6"]);?>" value="<?php echo $_POST["txtGradesSecond6"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird6" style="border:none" size="<?php echo strlen($_POST["txtGradesThird6"]);?>" value="<?php echo $_POST["txtGradesThird6"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject7" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject7"]);?>" value="<?php echo $_POST["txtGradesSubject7"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst7" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst7"]);?>" value="<?php echo $_POST["txtGradesFirst7"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond7" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond7"]);?>" value="<?php echo $_POST["txtGradesSecond7"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird7" style="border:none" size="<?php echo strlen($_POST["txtGradesThird7"]);?>" value="<?php echo $_POST["txtGradesThird7"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject8" style="border:none" size="<?php echo strlen($_POST["txtGradesSubject8"]);?>" value="<?php echo $_POST["txtGradesSubject8"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst8" style="border:none" size="<?php echo strlen($_POST["txtGradesFirst8"]);?>" value="<?php echo $_POST["txtGradesFirst8"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond8" style="border:none" size="<?php echo strlen($_POST["txtGradesSecond8"]);?>" value="<?php echo $_POST["txtGradesSecond8"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird8" style="border:none" size="<?php echo strlen($_POST["txtGradesThird8"]);?>" value="<?php echo $_POST["txtGradesThird8"]; ?>"/></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divEmergencyContact">
<h4>11. Emergency Contact Information</h4>
<table>
	<tr>
		<td><b>Name of Parent or Guardian</b></td>
		<td><input type="text" id="txtParentName" style="border:none" size="<?php echo strlen($_POST["txtParentName"]);?>" value="<?php echo $_POST["txtParentName"]; ?>"/></td>
	</tr><tr>
		<td><b>Relationship to Candidate</b></td>
		<td><input type="text" id="txtParentRelation" style="border:none" size="<?php echo strlen($_POST["txtParentRelation"]);?>" value="<?php echo $_POST["txtParentRelation"]; ?>"/></td>
	</tr><tr>
		<td><b>Address of Parent or Guardian</b></td>
		<td><input type="text" id="txtParentAddress" style="border:none" size="<?php echo strlen($_POST["txtParentAddress"]);?>" value="<?php echo $_POST["txtParentAddress"]; ?>"/></td>
	</tr><tr>
		<td><b>Tel:</b><input type="text" id="txtParentPhone" style="border:none" size="<?php echo strlen($_POST["txtParentPhone"]);?>" value="<?php echo $_POST["txtParentPhone"]; ?>"/></td>
		<td><b>E-mail:</b><input type="text" id="txtParentEMail" style="border:none" size="<?php echo strlen($_POST["txtParentEMail"]);?>" value="<?php echo $_POST["txtParentEMail"]; ?>"/></td>
	</tr><tr>
		<td><b>Occupation of Parent or Guardian</b></td>
		<td><input type="text" id="txtParentOccupation" style="border:none" size="<?php echo strlen($_POST["txtParentOccupation"]);?>" value="<?php echo $_POST["txtParentOccupation"]; ?>"/></td>
	</tr>
</table>
<br/>
</div>

<div id="divProgram">
<h4>12. Program You Intend to Study</h4>
	<input type="radio" id="rdoMLA" name="program" value="MLA" <?php if($_POST["program"]=="MLA"){echo "checked";}?>/>
	Medical Laboratory Assistant (MLA)
	<br/>
	<input type="radio" id="rdoMLT" name="program" value="MLT" <?php if($_POST["program"]=="MLT"){echo "checked";}?>/>
	Medical Laboratory Technitian (MLT)
	<br/>
	<input type="radio" id="rdoDMLT" name="program" value="DMLT" <?php if($_POST["program"]=="DMLT"){echo "checked";}?>/>
	Medical Laboratory Technologist (DMLT)
<br/><br/><br/>
</div>

<div id="divSignature">
<table>
	<tr>
		<td width="450px"><b>Signature of Applicant:________________________________</b></td>
		<td width="100px"><b>Date:_______________</b></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divDeclaration">
	<center><h3>DECLARATION BY WITNESS</h3></center>
	
	<p>
	This declaration should be signed by someone of high repute who should also
	endorse one of the passport-sized photographs on the reverse side.
	This person should be a Senior Public Servant/Clergyman/Lawyer/Medical Practitioner.
	The applicantion will not be valid if this is not signed.
	<br/><br/>
	I certify that the photograph endorsed by me is the true likeness of the applicant
	________________________________
	who is personally known to me.
	<br/><br/>
	I have inspected his/her certificates and I am satisfied that the names on them conform
	to those by which, to the best of my knowledge, he/she is officially known.
	</p>
	<br/>
<table>
	<tr>
		<td width="450px">Signature:________________________________</td>
		<td width="100px">Date:_______________</td>
	</tr>
</table>
<br/><br/>
<table>
	<tr>
		<td>Name:</td>
		<td><input type="text" id="txtWitnessName" style="border:none" size="<?php echo strlen($_POST["txtWitnessName"]);?>" value="<?php echo $_POST["txtWitnessName"]; ?>"/></td>
	</tr><tr>
		<td>Status:</td>
		<td><input type="text" id="txtWitnessStatus" style="border:none" size="<?php echo strlen($_POST["txtWitnessStatus"]);?>" value="<?php echo $_POST["txtWitnessStatus"]; ?>"/></td>
	</tr><tr>
		<td>Address:</td>
		<td><input type="text" id="txtWitnessAddress" style="border:none" size="<?php echo strlen($_POST["txtWitnessAddress"]);?>" value="<?php echo $_POST["txtWitnessAddress"]; ?>"/></td>
	</tr>
</table>
<br/>
</div>

<div id="divOfficialUse">
<table class="outlined" width="550px">
	<tr>
		<td colspan="2" align="center"><b>For Official Use Only</b></td>
	</tr><tr>
		<td width="50%"><br/>Receipt No._____________________<br/><br/>Date:__________________________<br/><br/></td>
		<td align="center" valign="top">Qualification vetted by</td>
	</tr><tr>
		<td><br/>Program Offered:</td>
		<td><br/>Signature:</td>
	</tr>
</table>
</div>
</div>
</body>
</html>